<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }

        .ol-zoomslider {
            top: 7.5em;
            background-color: #652e806c;
        }

        /* 鼠标位置控件层样式设置 */
        #mouse-position {
            position: absolute;
            left:50%;
            transform: translateX(-50%);
            bottom: 20px;
            width: 200px;
            height: 20px;
            /*在地图容器中的层，要设置z-index的值让其显示在地图上层*/
            z-index: 2000;
        }

        /* 鼠标位置信息自定义样式设置 */
        .custom-mouse-position {
            color: red;
            font-size: 16px;
            font-family: "微软雅黑";
        }
    </style>
</head>

<body>
    <div id="mouse-position">
    </div>
    <div id="map">

    </div>
    <script>
        /* 第三方的地图 */
        var gaodeMapLayer = new ol.layer.Tile({
            title: "高德地图-矢量图层",
            source: new ol.source.XYZ({
                url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });
        const map = new ol.Map({
            target: "map",
            layers: [gaodeMapLayer],
            view: new ol.View({
                center: [114.30, 30.50],
                zoom: 6,
                projection: "EPSG:4326"
            })
        })
        const navControl = new ol.control.ZoomToExtent({
            extent: [
                110, 30,
                160, 30
            ]
        })
        map.addControl(navControl)
        var zoomslider = new ol.control.ZoomSlider();
        map.addControl(zoomslider);

        //实例化鼠标位置控件（MousePosition）
        var mousePositionControl = new ol.control.MousePosition({
            //坐标格式
            coordinateFormat: ol.coordinate.createStringXY(4),
            //地图投影坐标系（若未设置则输出为默认投影坐标系下的坐标）
            projection: 'EPSG:4326',
            //坐标信息显示样式类名，默认是'ol-mouse-position'
            className: 'custom-mouse-position',
            //显示鼠标位置信息的目标容器
            target: document.getElementById('mouse-position'),
            //未定义坐标的标记
            undefinedHTML: '&nbsp;'
        });
        map.addControl(mousePositionControl)

    </script>
</body>

</html>